
local module = _G["BlinkHealthTextModule"]

if select(2, UnitClass("player")) ~= "SHAMAN" or not module then return end

local L_MAELSTROM_WEAPON = "Maelstrom Weapon"
if GetLocale()=="koKR" then
L_MAELSTROM_WEAPON = "소용돌이치는 무기"
end

module.config = {
	[L_MAELSTROM_WEAPON] = {
		spellid = 51530
	},
}

function module:init()
	self.addon.mainFrame:RegisterEvent("PLAYER_ALIVE")
	self.addon.mainFrame:RegisterEvent("LEARNED_SPELL_IN_TAB")
	self.addon.mainFrame:RegisterEvent("CHARACTER_POINTS_CHANGED")
	self:update()
end

function module:update()
	self.primary = GetSpecialization()
	for auraName, t in pairs(self.config) do
		if t.talent and t.talent > 0 then
			local name, iconTexture, tier, column, selected, available = GetTalentInfo(t.talent);
			if name and available then
				self.config[auraName].use = true
				if t.event and self.addon and self.addon.mainFrame then
					self.addon.mainFrame:RegisterEvent(t.event)
				end
			end
		else
			self.config[auraName].use = false
			if IsPlayerSpell(t.spellid) then
				self.config[auraName].use = true
				if t.event and self.addon and self.addon.mainFrame then
					self.addon.mainFrame:RegisterEvent(t.event)
				end
			end
		end
	end
end

function module:LEARNED_SPELL_IN_TAB(...)
	self:update()
end
module.CHARACTER_POINTS_CHANGED = module.LEARNED_SPELL_IN_TAB
function module:PLAYER_ALIVE(...)
	self.addon.mainFrame:UnregisterEvent("PLAYER_ALIVE")
	self:update()
end

function module:getTargetText()
	local text = ""
	--local name, rank, icon, count, debufType, duration, expirationTime
	--local r, g, b = 1, 1, 1

	if self.config[L_MAELSTROM_WEAPON].use then
		text = self:getAuraCount("player", L_MAELSTROM_WEAPON, "HELPFUL")
	end
	return text
end
